/****
 *
 * $Id: file.h,v 1.6 2009/09/29 23:16:58 rdilley Exp $
 *
 * Copyright (c) 2009, Ron Dilley
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 *   - Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 *   - Redistributions in binary form must reproduce the above copyright
 *     notice, this list of conditions and the following disclaimer in
 *     the documentation and/or other materials provided with the
 *     distribution.
 *   - Neither the name of Uberadmin/BaraCUDA/Nightingale nor the names of
 *     its contributors may be used to endorse or promote products derived
 *     from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
 * TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 ****/

#ifndef FILE_DOT_H
#define FILE_DOT_H

/****
 *
 * includes
 *
 ****/

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>
#include "hash.h"
#include "util.h"

/****
 *
 * defines
 *
 ****/

#define MAX_PT_LEN 29 /* 14 * 2 for NTLM */
#define MAX_HASH_LEN 16
#define MAX_RBUF_LEN 4096
#define MAX_PLAINTEXT_LEN 256
#define MAX_PASSWORD_LEN 32

#define HASH_TYPE_MD4 1
#define HASH_TYPE_MD5 2
#define HASH_TYPE_SHA1 3
#define HASH_TYPE_NTLM 4

#define CRACK_METHOD_DICT 1
#define CRACK_METHOD_RAINBOW 2
#define CRACK_METHOD_BRUTE 3
#define CRACK_METHOD_BRUTE_GPU 4
#define CRACK_METHOD_RAINBOW_GPU 5

#ifndef MAX_PATH_LEN
# define MAX_PATH_LEN 1024
#endif

#ifndef NTLM_HASH_LEN
# define NTLM_HASH_LEN 16
#endif

/****
 *
 * typedefs & structs
 *
 ****/

/* linked list to store unknown hashes */
struct hashList_s {
  int type;
  int len;
  uint8_t hValue[MAX_HASH_LEN+1];
  struct hashList_s *next;
};

/* structure to store indexed hash and plaintext data */
typedef struct {
  time_t eTime;
  int crackMethod;
  int hType;
  int hLen;
  char h[MAX_HASH_LEN];
  char pt[MAX_PLAINTEXT_LEN];
} hData_t;

/* work unit structure */
/* XXX NTML specific */
typedef struct {
  char pt[MAX_PT_LEN];
  char ptLen;
  char uHash[NTLM_HASH_LEN];
  char uhLen;
  uint32_t key;
} workUnit_t;

/* plaintext state structures */

/* pure brute force state */
typedef struct {
  char tokenBuf[MAX_PASSWORD_LEN+1];
  unsigned char ptTokens[MAX_PASSWORD_LEN];
  int ptCurLen;
} pureBruteForceState_t;

/* known plaintext linked list */
struct knownPlainText_s {
  char pt[MAX_PASSWORD_LEN+1];
  int ptLen;
  struct knownPlainText_s *next;
};

/* token frequency data from learning */
struct token_s {
  unsigned char token;
  unsigned long count;
  struct token_s *prev;
  struct token_s *next;
};

/****
 *
 * function prototypes
 *
 ****/

int saveGuessedHash( workUnit_t *workUnit );
int loadKnownHashes( const char *fName );
int loadUnknownHashes( const char *fName );
int openPwDict( const char *fName );
int loadPwDict( workUnit_t *workUnits, int loadCount );
int saveState( char *fName );
int loadState( char *fName );

#endif /* end of FILE_DOT_H */

